package com.company.strategy;

public class Sort<T> {

    public int[] sort(int[] a) {
        for (int i = 0; i < a.length - 1; i++) {
            for (int j = i + 1; j < a.length; j++) {
                if (a[i] > a[j]) {
                    int t = a[i];
                    a[i] = a[j];
                    a[j] = t;
                }
            }
        }
        return a;
    }

    //    public static void  sortObject(MyComparable[]c){
//        for (int i =0;i<c.length-1;i++){
//            int minPos = i;
//            for(int j = i+1;j<c.length;j++){
//                minPos = c[j].compareTo(c[minPos]) == -1? j:minPos;
//            }
//            swap(c,i,minPos);
//        }
//    }
//
//    public static void swap(MyComparable[]c ,int i,int j){
//        MyComparable temp = c[i];
//        c[i] = c[j];
//        c[j] = temp;
//    }
    public void sortObject(T[] c, MyComparator<T> comparator) {
        for (int i = 0; i < c.length - 1; i++) {
            int minPos = i;
            for (int j = i + 1; j < c.length; j++) {
                minPos = comparator.compare(c[j], c[minPos]) == -1 ? j : minPos;
            }
            swap(c, i, minPos);
        }
    }

    public void swap(T[] c, int i, int j) {
        T temp = c[i];
        c[i] = c[j];
        c[j] = temp;
    }

}
